using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HermesPortal.Core;
using HermesPortalUI; 
public partial class Realms_Controls_RealmView : System.Web.UI.UserControl
{
    private int _realmID=0;
    private int _sagaId = 0;
    private bool _isSummary = false;
    public int SagaID
    {
        get { return _sagaId; }
        set { _sagaId = value; }
    }
 
    public int RealmID
    {
        get { return _realmID; }
        set { _realmID = value; }
    }

    /// <summary>
    /// will not load description field
    /// </summary>
    public bool IsSummary
    {
        get { return _isSummary; }
        set { _isSummary = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        
       
       
    }

    #region Helper Methods
    public void BindControls()
    {
        Realm realm = RealmServices.GetRealm(this.RealmID);
        if (realm != null && realm.SagaID == SagaID)
        {
            lblTitle.Text = realm.Title;
            lblRealmSummary.Text = realm.Summary;
            if (!IsSummary)
            {
                lblRealmDescription.Text = realm.Description;
                
            }
            else
                lnkDetailView.NavigateUrl = String.Format(@"~/Realms/Realm.aspx?SagaID={0}&RealmID={1}", realm.SagaID, realm.RealmID);
            
            lnkDetailView.Visible = IsSummary;
  
            lblViewNotice.Visible = realm.IsPrivate;  
            // add link to parent node if exists
            if (realm.ParentID > 0)
            {
                lnkParentNode.NavigateUrl = String.Format(@"~/Realms/Realm.aspx?SagaID={0}&RealmID={1}", realm.SagaID, realm.ParentID);
                lnkParentNode.Visible = true;
            }
            else
                lnkParentNode.Visible = false;

             StringDictionary listSubrealms = RealmServices.GetRealmSubNodesInfo(this.SagaID, this.RealmID,  ((PageBase)this.Page).Creator.Id);      
            if (listSubrealms.Count > 0 )
            {
                listSubNodes.DataSource = listSubrealms;
                listSubNodes.DataBind();
            }

        }
        else
        {
            Response.Redirect(Request.ApplicationPath + "/Default.aspx");
        }
    }


   
    #endregion 
}
